package com.auxgroup.hr.front.site.co.hireperson;

import com.auxgroup.hr.front.commons.BaseRetCode;
import com.auxgroup.hr.front.commons.utils.ObjectFieldUtils;
import com.auxgroup.hr.front.commons.vo.BaseResponseVO;
import com.auxgroup.hr.front.dao.domain.PsCHireJyxyT;
import com.auxgroup.hr.front.dao.domain.PsCHirePrimaryClass;
import com.auxgroup.hr.front.dozer.IObjectMapper;
import com.auxgroup.hr.front.service.hireperson.HireJyxyTService;
import com.auxgroup.hr.front.site.co.BaseCO;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * 档案信息CO
 */
@RestController
@RequestMapping("${auxgroup.hr.contextPath}/hireJyxy")
public class HireJyxyCO extends BaseCO {

	private static final Logger logger = LoggerFactory.getLogger(HireJyxyCO.class);

	@Autowired
	public HireJyxyTService hireJyxyTService;

	@Resource(name = "dozerMapper")
	protected IObjectMapper objectMapper;

	/**
	 * 获取入职人员资格证书
	 * @param rsHireId
	 * @return
	 */
	@GetMapping(value = "/getOne")
	public BaseResponseVO getOne(String rsHireId) {
		logger.info("getHireZcgl param= {}", rsHireId);
		if(StringUtils.isBlank(rsHireId)){
			return buildRespone(BaseRetCode.CODE_ERROR_RSHIREID_BLANK);
		}
		PsCHireJyxyT hireZcgl = hireJyxyTService.getByHire(rsHireId);
		return buildRespone(hireZcgl);
	}
	
	/**
	 * 保存档案信息
	 * @return
	 */
	@PostMapping(value = "/save")
	public BaseResponseVO save(PsCHireJyxyT jyxy) {
		logger.info("save jyxy param= {}", jyxy);
		if(StringUtils.isBlank(jyxy.getRsHireId())){
			return buildRespone(BaseRetCode.CODE_ERROR_RSHIREID_BLANK);
		}

		ObjectFieldUtils.handleNullValue(jyxy);
		hireJyxyTService.save(jyxy);
		return buildRespone(true);
		
	}
	
	/**
	 * 删除档案信息
	 * @return
	 */
	@PostMapping(value = "/del")
	public BaseResponseVO del(String rsHireId) {
		logger.info("delHireZcgl param= {}", rsHireId);
		if(StringUtils.isBlank(rsHireId)){
			return buildRespone(BaseRetCode.CODE_ERROR_RSHIREID_BLANK);
		}
		Boolean isdel = hireJyxyTService.delete(rsHireId);
		return buildRespone(isdel);
	}
	
}
